package org.phnq.babel.log;

public class Logger
{
	private int nativeRef;

	public Logger(Class catClass)
	{
		this(catClass.getName());
	}
	
	public Logger(String category)
	{
		this.nativeRef = initNative(category);
	}

	protected void finalize() throws Throwable
	{
		dispose();
	}
	
	public void dispose()
	{
		if(this.nativeRef == 0)
			return;
		
		destroyNative(this.nativeRef);
		this.nativeRef = 0;
	}
	
	public void debug(String msg)
	{
		debug(nativeRef, msg);
	}

	public void info(String msg)
	{
		info(nativeRef, msg);
	}

	public void warning(String msg)
	{
		warning(nativeRef, msg);
	}

	public void error(String msg)
	{
		error(nativeRef, msg);
	}

	public void critical(String msg)
	{
		critical(nativeRef, msg);
	}
	
	private native int initNative(String category);
	private native void destroyNative(int nativeRef);
	private native void debug(int nativeRef, String msg);
	private native void info(int nativeRef, String msg);
	private native void warning(int nativeRef, String msg);
	private native void error(int nativeRef, String msg);
	private native void critical(int nativeRef, String msg);
}
